const Joi = require('joi')

// user模块验证规则 
// 注册 
const regUserSchema = Joi.object({
    username: Joi.string()
                .alphanum()
                .min(3)
                .max(30)
                .required(),
    password: Joi.string().pattern(/^[a-zA-Z0-9]{6,12}$/).min(8).max(16).required(),
    repeat_password: Joi.ref('password'),
    phone: Joi.string().pattern(/^[0-9]{0,5}[-]{0,1}[0-9]{5,12}$/),
    email: Joi.string().email({minDomainSegments: 2, tlds: {allow: ['com', 'net']}}) 
}).with('password', 'repeat_password')

// 登录
const loginSchema = Joi.object({
    username: Joi.string()
                .alphanum()
                .min(3)
                .max(30)
                .required(),
    password: Joi.string().pattern(/^[a-zA-Z0-9]{6,12}$/).required(),
    code: Joi.string()
            .alphanum()
            .min(4)
            .max(4)
            .required(),
    tm: Joi.string()
            .alphanum()
            .min(32)
            .max(32)
            .required(),
})

// 查询用户列表  
const userListSchema = Joi.object({
    pageSize: Joi.number(),
    currentPage: Joi.number(),
    where: Joi.object(),
    sort: Joi.object() 
})

// 删除用户
const userDeleteSchema = Joi.object({
    ids: Joi.array() 
})




exports.regUser = regUserSchema 
exports.login = loginSchema
exports.userList = userListSchema
exports.userDelete = userDeleteSchema
